Lab Practices have the purpose of reviewing the previous applied video lecture(s) and introducing new content to improve students’ empirical macroeconomic analysis using R and RStudio.
In this practice, you will produce interactive charts using the
{plotly} package.
There is 1 problem, worth 10 points.
Assignment due April 10 (M), before class.
Points Possible: 10
You have 1 week to complete this assignment. See our
course syllabus for late submissions policies.
Be honest. Don’t cheat.
As a Skidmore student, always recall your votes of academic
integrity, and the Honor Code you have abided by:
“I hereby accept membership in the Skidmore College community and, with full realization of the responsibilities inherent in membership, do agree to adhere to honesty and integrity in all relationships, to be considerate of the rights of others, and to abide by the college regulations.”
Have fun!
The plotly package works really well with
ggplot2. In practice, we set up our plots with
ggplot2, and then we use the ggplotly()
function to make it interactive.
A few weeks ago, you produced a chart to visualize the U.S. economy’s balance on current account. Based on what we’ve learned in the last video lecture, its interactive version looks like so:
library(tidyverse)
library(ggthemes)
library(plotly)
theme_set(theme_light())
us_current_acct <- read_csv("current_account_balance.csv")
plot_us <- us_current_acct %>%
mutate(period = seq(as.Date("1947-01-01"), by = "quarter", length.out = 303)) %>%
ggplot(aes(x = period, y = current_account)) +
geom_line() +
labs(x = "",
y = "Billions of dollars",
title = "United States: Balance on current account, 1947Q1 - 2022Q3") +
geom_area(alpha = 0.3, fill = "#635f83")
plot_us %>%
ggplotly() %>%
layout(xaxis = list(rangeslider = list(visible = TRUE)))Now, it’s your turn!
Use this link
to download the current account balance (as a % of GDP) for the Euro
area. Reproduce the following interactive chart: